<nz-card class="m-b-2">
  <div class="common-search-wrap">
    <div class="common-search-forms">
      <div class="common-form-item">
        <label class="common-search-label">抽奖配置</label>
        <div class="common-search-conrol">
          <nz-select
            nzShowSearch
            nzAllowClear
            nzPlaceHolder="请选择抽奖配置"
            nzMode="multiple"
            [nzMaxTagCount]="1"
            [(ngModel)]="selectParams.configSelected"
            (nzScrollToBottom)="loadMore()"
            [nzDropdownRender]="renderTemplate"
          >
            <nz-option
              nzCustomContent
              *ngFor="let option of selectParams.configOptions"
              [nzLabel]="option.activityName"
              [nzValue]="option.id">
              <span>【{{ option.status | placeStatus: 'text' }}】</span>
              <span>{{ option.activityName }}</span>
            </nz-option>
          </nz-select>
          <ng-template #renderTemplate>
            <nz-spin *ngIf="selectParams.loading"></nz-spin>
          </ng-template>
        </div>
      </div>

      <div class="common-form-item">
        <label class="common-search-label">状态</label>
        <div class="common-search-conrol">
          <nz-select
            nzShowSearch
            nzAllowClear
            nzMode="multiple"
            [nzMaxTagCount]="1"
            nzPlaceHolder="请选择状态"
            [(ngModel)]="backStatusArr">
            <nz-option nzLabel="退回成功" nzValue="1"></nz-option>
            <nz-option nzLabel="退回失败" nzValue="2"></nz-option>
            <nz-option nzLabel="无需退回" nzValue="3"></nz-option>
            <nz-option nzLabel="正常" nzValue="4"></nz-option>
          </nz-select>
        </div>
      </div>

      <div class="common-form-item">
        <label class="common-search-label">中奖时间</label>
        <div class="common-search-conrol">
          <nz-range-picker [(ngModel)]="prizeDates" (ngModelChange)="onDateChange($event)"></nz-range-picker>
        </div>
      </div>

      <div class="common-form-item" [hidden]="!isCollapse">
        <label class="common-search-label">奖品券码</label>
        <div class="common-search-conrol">
          <input nz-input placeholder="请输入奖品券码" [(ngModel)]="seachParams.couponNo" />
        </div>
      </div>

      <div class="common-form-item" [hidden]="!isCollapse">
        <label class="common-search-label">订单编号</label>
        <div class="common-search-conrol">
          <input nz-input placeholder="请输入订单编号" [(ngModel)]="seachParams.orderNum" />
        </div>
      </div>

      <div class="common-form-item">
        <div class="common-search-conrol">
          <button nz-button nzType="primary" class="m-r-8" [nzLoading]="tableParams.tableLoading" (click)="seachData()">查询</button>
          <button nz-button nzType="default" (click)="resetData()">重置</button>
          <button nz-button nzType="link" (click)="isCollapse = !isCollapse">
            {{ isCollapse ? '收起' : '展开' }}<i nz-icon [nzType]="isCollapse ? 'up' : 'down'" nzTheme="outline"></i>
          </button>
        </div>
      </div>
    </div>
  </div>
</nz-card>

<nz-card class="pagination-wrap-position">
  <div class="operation-wrap p-b-10">
    <button
      nz-button
      nzType="primary"
      [disabled]="!tableData?.length"
      [nzLoading]="exportLoading"
      (click)="exportTable()">
      <i nz-icon nzType="download"></i>导出
    </button>
  </div>

  <!-- Table -->
  <div class="table-wrap">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzOuterBordered
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableParams.tableLoading"
      [nzData]="tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableParams.total"
      [nzPageIndex]="tableParams.page"
      [nzPageSize]="tableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
    >
      <thead>
        <tr>
          <th nzAlign="center" nzWidth="120px">ID</th>
          <th nzAlign="center">状态</th>
          <th nzAlign="center">用户ID</th>
          <th nzAlign="center">关联订单号</th>
          <th nzAlign="center">抽奖配置</th>
          <th nzAlign="center">奖品类型</th>
          <th nzAlign="center">奖品名称</th>
          <th nzAlign="center">中奖时间</th>
          <th nzAlign="center">用户奖品编码</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <td nzAlign="center">{{ data.id }}</td>
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.backStatus | returnStatus: 'color'}">
              {{ data.backStatus | returnStatus: 'text' }}
            </span>
          </td>
          <td nzAlign="center">
            <a nz-button nzType="link" nzSize="small" [routerLink]="['/customer/tabs', data.userId, 0]" target="_blank">{{ data.userId }}</a>
          </td>
          <td nzAlign="center">
            <a
              nz-button
              nzType="link"
              target="_blank"
              [disabled]="!data.orderNum"
              [routerLink]="['/order/accDetails', data.orderId]">
              {{ data.orderNum || '-' }}
            </a>
          </td>
          <td nzAlign="center">{{ data.activityName || '-' }}</td>
          <td nzAlign="center">
            <span>{{ data.type | prizeStatus }}</span>
          </td>
          <td nzAlign="center">{{ data.prizeName || '-' }}</td>
          <td nzAlign="center">{{ data.createTime || '-' }}</td>
          <td nzAlign="center">
            <ng-container *ngIf="data.type === 2;else templateType">
              <a
                nz-button
                nzType="link"
                target="_blank"
                [disabled]="!data.couponNo"
                [routerLink]="['/sell/userCoupon']"
                [queryParams]="{id: data.couponNo}">
                {{ data.couponNo || '-' }}
              </a>
            </ng-container>
            <ng-template #templateType>
              <span>{{ data.couponNo || '-' }}</span>
            </ng-template>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ tableParams.total }} 条</ng-template>
  </div>
</nz-card>